#include "CollectableItemsList.h"


CollectableItemsList::CollectableItemsList(void)
	:NUM_CANDIES(250)
	,NUM_SPECIAL_CANDIES(4)
{
	mCandies		= new Candy*[NUM_CANDIES];
	mSpecialCandies = new Candy*[NUM_SPECIAL_CANDIES];

	for(int i = 0; i < NUM_CANDIES + NUM_SPECIAL_CANDIES; i++)
	{
		if(i < NUM_CANDIES)
			mCandies[i] = new Candy();
		else
			mSpecialCandies[i-NUM_CANDIES] = new Candy(SPECIAL_CANDY);
	}

	candyImages[CANDY]			= new Bitmap("data\\candy.tga");
	candyImages[SPECIAL_CANDY]	= new Bitmap("data\\special_candy.tga");
}

CollectableItemsList::CollectableItemsList(Background* bg)
	:NUM_CANDIES(((NUM_TILES - bg->getNumWall())*2/3)-4)
	,NUM_SPECIAL_CANDIES(4)
{
	mCandies		= new Candy*[NUM_CANDIES];
	mSpecialCandies = new Candy*[NUM_SPECIAL_CANDIES];

	for(int i = 0; i < NUM_CANDIES + NUM_SPECIAL_CANDIES; i++)
	{
		if(i < NUM_CANDIES)
			mCandies[i] = new Candy();
		else
			mSpecialCandies[i-NUM_CANDIES] = new Candy(SPECIAL_CANDY);
	}


	candyImages[CANDY]			= new Bitmap("data\\candy.tga");
	candyImages[SPECIAL_CANDY]	= new Bitmap("data\\special_candy.tga");
}


CollectableItemsList::~CollectableItemsList(void)
{
	for(int i = 0; i < CANDY_COUNT; i ++)
		delete candyImages[i];

	for(int i = 0; i < NUM_SPECIAL_CANDIES; i++)
		delete mSpecialCandies[i];
	delete [] mSpecialCandies;
	
	for(int i = 0; i < NUM_CANDIES; i++)
		delete mCandies[i];
	delete mCandies;
}

void CollectableItemsList::DrawTo(Bitmap* renderTarget, int hPadding, int vPadding)
{
	Candy* candy;
	for(int i = 0; i < NUM_CANDIES + NUM_SPECIAL_CANDIES; i++)
	{
		if(i < NUM_CANDIES)	{candy = mCandies[i];					}
		else				{candy = mSpecialCandies[i-NUM_CANDIES];}

		if(candy->isActive() 
			&&
			candy->getXcoord() >= 0 && candy->getYcoord() >= 0)
		{
			candyImages[candy->getType()]->DrawTo(renderTarget, hPadding+candy->getXcoord(), vPadding+candy->getYcoord());
		}

	}
}